package cn.dengta.context.config;

import cn.dengta.context.ContextRefreshListener;
import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import me.codeplayer.util.EasyDate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 在服务注册至 Nacos 客户端时，在服务详情中增加相应的元数据，增加服务注册时间
 * <p>
 * https://juejin.cn/post/6987533663613386788
 */
@Configuration
@ConditionalOnNacosDiscoveryEnabled
public class NacosConfig implements ContextRefreshListener {

	/** 应用启动时间 */
	public static final long START_TIME = System.currentTimeMillis();

	@Bean
	public NacosDiscoveryProperties nacosProperties() {
		NacosDiscoveryProperties nacosDiscoveryProperties = new NacosDiscoveryProperties();
		nacosDiscoveryProperties.getMetadata().put("startup.time", new EasyDate(START_TIME).toLongString());
		return nacosDiscoveryProperties;
	}

}
